import axios from 'axios'
import { BASE_URL, TIME_OUT } from './config'

export function request(config) {
  const instance = axios.create({
    baseURL: BASE_URL,
    timeout: TIME_OUT
  })

  instance.interceptors.request.use(
    config => {
      // Do something before request is sent
      return config
    },
    error => {
      // Do something with request error
      return Promise.reject(error)
    }
  )

  instance.interceptors.response.use(
    response => {
      // Do something before response is sent
      return response.data
    },
    error => {
      // Do something with response error
      return Promise.reject(error)
    }
  )
  return instance(config)
}
